package com.app.service.impl;

import com.app.mapper.jiuquan.ProjectMapper;
import com.app.model.ProjectModel;
import com.app.model.ProjectModel;
import com.app.service.ProjectService;
import com.app.util.DateMaskingUtils;
import com.app.util.StringTool;
import com.app.vo.ProjectVo;
import com.app.vo.ProjectVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//创业项目
@Service
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, ProjectModel> implements ProjectService {
    @Autowired
    private ProjectMapper projectMapper;

    //查询创业项目列表
    @Override
    public ProjectVo getProjectList(Integer page, Integer limit, String projectName, String startTime, String endTime, Double investment) {
        Page<ProjectModel> page1 = new Page<>(page, limit);
        QueryWrapper<ProjectModel> qw = new QueryWrapper<>();
        //根据项目名称模糊查询
        if (StringTool.isNotEmpty(projectName)) {
            qw.like("project_name", projectName);
        }
        //根据时间查询
        if (StringTool.isNotEmpty(startTime) && StringTool.isNotEmpty(endTime)) {
            qw.ge("release_time", startTime);
            qw.le("release_time", endTime);
        }
        //根据金额查询
        if (investment != null) {
            qw.eq("investment",investment);
        }
        qw.orderByDesc("id");
        Page<ProjectModel> projectPage = projectMapper.selectPage(page1, qw);

        List<ProjectModel> projectList = projectPage.getRecords();
        for (ProjectModel project : projectList) {
            String phone = project.getPhone();
            String phoneMi = DateMaskingUtils.mobileEncrypt(phone);
            project.setPhoneMi(phoneMi);
        }
        long count = projectPage.getTotal();
        ProjectVo projectVo = new ProjectVo();
        projectVo.setList(projectList);
        projectVo.setCount((int) count);
        return projectVo;
    }
}
